from pathlib import Path
import re

daka_dict = {}

pathlist = Path("daka").glob('**/*.txt')
for path in pathlist:
     path_in_str = str(path)
     #print(f'reading [{path_in_str}] ...')

     with open(path_in_str) as f:
         for line in f:
             match = re.search(r'学号[:：]?\s*(\d{3}[a-zA-Z]\d{3})', line, re.IGNORECASE)
             if not match:
                 continue

             no = match.group(1)
             if no in daka_dict:
                 daka_dict[no].add(f)
             else:
                 day_set = set()
                 day_set.add(f)
                 daka_dict[no] = day_set


with open('res.txt', 'w') as f:
    for k, v in sorted(daka_dict.items()):
        line = '{} 打卡{}天\n'.format(k, len(v))
        f.write(line)
